/*
 * author      : 吴中勤 
 * date        : 2018/12/18
 * description : TODO
 */

package org.wzq.learn;

// stack overflow


/*

cd src
javac org/wzq/learn/JVMStackSOF.java
java -Xss160k org/wzq/learn/JVMStackSOF

【output】
stack depth = 771
Exception in thread "main" java.lang.StackOverflowError
        at org.wzq.learn.JVMStackSOF.stackLeak(JVMStackSOF.java:21)
        at org.wzq.learn.JVMStackSOF.stackLeak(JVMStackSOF.java:22)
           ...

*/
public class JVMStackSOF {
    private int stackDepth = 1;
    public void stackLeak() {
        stackDepth++;
        stackLeak();
    }

    public static void main(String[] args) {
        JVMStackSOF oom = new JVMStackSOF();
        try {
            oom.stackLeak();
        } catch (Throwable e) {
            System.out.println("stack depth = " + oom.stackDepth);
            throw e;
        }
    }
}
